package com.Servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jdbc.Jdbc;

/**
 * Servlet implementation class workcontract
 */
@WebServlet("/workcontract2")
public class workcontract2 extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public workcontract2() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		
		String id = request.getParameter("sid");
		String cname = request.getParameter("chinesename");
		String ename = request.getParameter("englishname");
		String sex = request.getParameter("sex");
		String birthday = request.getParameter("birthday");
		String counselor = request.getParameter("counselor");
		String pcounselor = request.getParameter("phonecounselor");
		String username = (String) request.getSession().getAttribute("username");
		String insert = "insert into contract( id, chinesename,englishname,sex,birthday,counselor,phonecounselor,username)values('" + id + "','" + cname + "','" + ename + "','" + sex + "','" + birthday + "','" + counselor + "','" + pcounselor + "','" + username
				+ "')";
		System.out.println(insert);
		Jdbc j1 = null;

		try {
			j1 = new Jdbc(insert);

		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			System.out.println("haha1");
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			request.getRequestDispatcher("contract_sql_fail.jsp").forward(request, response);
		}
        //在添加了合同信息后，就要给每个合同的学生添加到一个签到表中，以便后来再检查该学生的签到记录
		//签到表为check_info,并且在其中记录签到的日期
		
		request.getRequestDispatcher("showsuccess.jsp").forward(request, response);

	}

}
